{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydantic import BaseModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import Union, Dict\n",
    "\n",
    "\n",
    "class JoinStatementElement(BaseModel):\n",
    "    text: str\n",
    "class SQL(BaseModel):\n",
    "    statements: Dict[str, Union[str, JoinStatementElement]] = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sql = SQL(statements={\"a\": \"abc\", \"b\": JoinStatementElement(text=\"bbb\")})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"statements\": {\n",
      "        \"a\": \"abc\",\n",
      "        \"b\": {\n",
      "            \"text\": \"bbb\"\n",
      "        }\n",
      "    }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "print(sql.json(indent=4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SQL(statements={'a': 'abc', 'b': JoinStatementElement(text='bbb')})"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SQL.parse_raw(sql.json())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.13 ('commodity-dev')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "0f05fcf9f70ae23b8c9cfadcfc27206bc43ba3c59d332393ab3442872b67cd24"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
